package cn.qidd.keep.member.model;

import cn.qidd.keep.domain.core.dict.MemberStatus;
import cn.qidd.keep.domain.document.QMember;
import cn.qidd.keep.domain.model.BaseSearch;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
public class SearchMemberParam extends BaseSearch {

    @ApiModelProperty("会员编号")
    private String memberNo;
    @ApiModelProperty("会员卡姓名")
    private String name;
    @ApiModelProperty("会员卡电话")
    private String mobile;
    @ApiModelProperty("会员状态")
    private MemberStatus memberStatus;

    @Override
    public BooleanBuilder generateSearchCondition() {
        BooleanBuilder builder = new BooleanBuilder();
        QMember qMember = QMember.member;
        if (StringUtils.isNotBlank(memberNo)) {
            builder.and(qMember.memberNo.eq(this.memberNo));
        }
        if (StringUtils.isNotBlank(name)) {
            builder.and(qMember.name.eq(this.name));
        }
        if (StringUtils.isNotBlank(mobile)) {
            builder.and(qMember.mobile.eq(this.mobile));
        }
        if (memberStatus != null) {
            builder.and(qMember.memberStatus.eq(this.memberStatus));
        }
        return builder;
    }
}
